{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "dbe605f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "随机森林模型的预测准确率： 0.94\n"
     ]
    }
   ],
   "source": [
    "#项目8-例8-2代码\n",
    "from sklearn.datasets import load_iris\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.ensemble import RandomForestClassifier #导入随机森林分类模块\n",
    "from sklearn.metrics import accuracy_score\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.colors import ListedColormap\n",
    "import numpy as np\n",
    "\n",
    "#拆分数据集\n",
    "x,y=load_iris().data[:,2:4],load_iris().target   \n",
    "x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=0,test_size=50)\n",
    "\n",
    "#训练模型\n",
    "model=RandomForestClassifier(n_estimators=10,random_state=0)\n",
    "model.fit(x_train,y_train)\n",
    "\n",
    "#评估模型\n",
    "pred=model.predict(x_test)\n",
    "ac=accuracy_score(y_test,pred)\n",
    "print(\"随机森林模型的预测准确率：\",ac)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "eb1886c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYMAAAEICAYAAAC9E5gJAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAei0lEQVR4nO3de5gcdZX/8ffJHcgQJgMsEEAICKJAUAIiRoEI+XmBrIDukxXkJhu5yY8fRn4gokGEBRZZUS4a+blhWR5RjLijKBBuunExF3ATuUNCMAMRkhAmCUlmMjPn90fVZHoq1V01PVXT3dOf1/PMk+7qb1edyZP06W/V+Z4yd0dEROrbkEoHICIiladkICIiSgYiIqJkICIiKBmIiAhKBiIiQk7JwMyGmdl9ZvZHM/tJkTGjzOw3Z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olIHlAyknj0LTAVuAN5rZlcDHye4ZvB8OOYw4HxgJcEF3iUEH+SXA9sTfMvfA7iucMdhueiPgZ+Y2anuvqLg5X2A14H3AF8guKNXEz2tm0UGnK4ZSN1y9y3u/m749E1gJvAAYdtfM/sisJ7g5iBfIfiw3pugG+RaghLU6929MBEMJ/iQf4jg+sLlwO/N7Doz2yO8a1tTeOzTCFpL/47g5jh35vjripSkmYFI8O2+zd2fN7NlwBwzW0twneBTwMsEJaO3E3zY30Rw6uh9BD33C+1HkDA+7+4vwdZ7Tl9IUEr6j8ATZrZvOG57YAbB3dw+YWYrCe77XJU3HJLBSy2sRTIUfvMfWTDjiL6+B8GtRj9BkAx+DzxJUK00BRjr7t8coHBFtlIyEBERXTMQERElAxERQclARERQMhAREZQMREQE+P/2ts6iC/QjNwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#画分类界面\n",
    "x1,x2=np.meshgrid(np.linspace(0,8,500),np.linspace(0,3,500))     #生成网格采样点\n",
    "x_new=np.stack((x1.flat,x2.flat),axis=1)  #将采样点作为测试点\n",
    "y_predict=model.predict(x_new)  #预测测试点的值\n",
    "y_hat=y_predict.reshape(x1.shape) #与x1设置相同的形状\n",
    "iris_cmap=ListedColormap([\"#ACC6C0\",\"#FF8080\",\"#A0A0FF\"])                   #设置分类界面的颜色\n",
    "plt.pcolormesh(x1,x2,y_hat,cmap=iris_cmap)                                    #绘制分类界面\n",
    "\n",
    "#绘制3种类别鸢尾花的样本点\n",
    "plt.scatter(x[y==0,0],x[y==0,1],s=30,c='g',marker='^')\n",
    "plt.scatter(x[y==1,0],x[y==1,1],s=30,c='r',marker='o')\n",
    "plt.scatter(x[y==2,0],x[y==2,1],s=30,c='b',marker='s')\n",
    "\n",
    "#设置坐标轴的名称并显示图形\n",
    "plt.rcParams['font.sans-serif']='Simhei'\n",
    "plt.xlabel('花瓣长度')\n",
    "plt.ylabel('花瓣宽度')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b70c2148",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b953408",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
